//
//  HomeTableViewCell.m
//  Topit
//
//  Created by dllo on 15/11/27.
//  Copyright © 2015年 YXY. All rights reserved.
//

#import "HomeTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation HomeTableViewCell
-(void)dealloc {
    [_desc release];
    [_name release];
    [_sbjName release];
    [_ts release];
    [_title release];
    [_images release];
    [_fnum release];
    [_cnum release];
    [_homeModel release];
    [_array release];
    [_briImage release];
    [_review release];
    [_focus release];

    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.images = [[UIImageView alloc] initWithFrame:CGRectZero];
        _images.contentMode = UIViewContentModeScaleAspectFill;
        _images.clipsToBounds = YES;
        [self addSubview:_images];
        [_images release];
        
        self.briImage = [[UIView alloc] initWithFrame:CGRectZero];
        _briImage.alpha = 0.4;
        _briImage.backgroundColor = [UIColor blackColor];
        [_briImage release];
        [self addSubview:_briImage];
        
        self.ts = [[UILabel alloc] initWithFrame:CGRectZero];
        _ts.font = [UIFont systemFontOfSize:10];
        _ts.textColor = [UIColor whiteColor];
        [self addSubview:_ts];
        [_ts release];
        
        self.title = [[UILabel alloc] initWithFrame:CGRectZero];
        _title.font = [UIFont systemFontOfSize:15];
        _title.textColor = [UIColor whiteColor];
        [self addSubview:_title];
        [_title release];
        
        self.name = [[UILabel alloc] initWithFrame:CGRectZero];
        _name.font = [UIFont systemFontOfSize:10];
        _name.backgroundColor = [UIColor redColor];
        _name.textColor = [UIColor whiteColor];
        _name.textAlignment = 1;
        [self addSubview:_name];
        [_name release];
        
        self.sbjName = [[UILabel alloc] initWithFrame:CGRectZero];
        _sbjName.font = [UIFont systemFontOfSize:8];
        _sbjName.textColor = [UIColor whiteColor];
        [self addSubview:_sbjName];
        [_sbjName release];
        
        self.desc = [[UILabel alloc] initWithFrame:CGRectZero];
        _desc.font = [UIFont systemFontOfSize:10];
        _desc.textColor = [UIColor whiteColor];
        _desc.numberOfLines = 2;
        [self addSubview:_desc];
        [_desc release];
        
        self.from = [[UILabel alloc] initWithFrame:CGRectZero];
        _from.font = [UIFont systemFontOfSize:10];
        _from.textColor = [UIColor grayColor];
        [self addSubview:_from];
        [_from release];
        
        self.fnum = [[UILabel alloc] initWithFrame:CGRectZero];
        _fnum.font = [UIFont systemFontOfSize:8];
        _fnum.textColor = [UIColor whiteColor];
        [self addSubview:_fnum];
        [_fnum release];
        
        self.cnum = [[UILabel alloc] initWithFrame:CGRectZero];
        _cnum.font = [UIFont systemFontOfSize:8];
        _cnum.textColor = [UIColor whiteColor];
        [self addSubview:_cnum];
        [_cnum release];

        
        self.focus = [[UIImageView alloc] initWithFrame:CGRectZero];
        _focus.image = [UIImage imageNamed:@"focus"];
        [self addSubview:_focus];
        [_focus release];
        
        self.review = [[UIImageView alloc] initWithFrame:CGRectZero];
        _review.image = [UIImage imageNamed:@"review"];
        [self addSubview:_review];
        [_review release];
    }
    return self;
}




-(void)setHomeModel:(HomeModel *)homeModel {
    if (_homeModel != homeModel) {
        [_homeModel release];
        _homeModel = [homeModel retain];
    }
    for (int i = 0; i < homeModel.dataSource.count; i++) {
        PictureModel *pictureModel = homeModel.dataSource[i];
        [_images sd_setImageWithURL:[NSURL URLWithString:pictureModel.icon[@"url"]]];
        _fnum.text = [NSString stringWithFormat:@"%@", pictureModel.fnum];
        _cnum.text = [NSString stringWithFormat:@"%@", pictureModel.cnum];
        _images.tag = i + 1000;
        [self.array addObject:_images];
    }
    
    _desc.text = homeModel.desc;

    _name.text = homeModel.name;

    _sbjName.text = homeModel.sbj[@"name"];

    _ts.text = homeModel.ts;

    _title.text = homeModel.title;

    _from.text = @"from";

    

}
-(NSMutableArray *)array {
    if (!_array) {
        self.array = [NSMutableArray arrayWithCapacity:0];
    }
    return _array;
}

-(void)layoutSubviews {
    [super layoutSubviews];
  
    
    _images.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - 10);
    _name.frame = CGRectMake(10, 0, 43, 15);
    _from.frame = CGRectMake(_name.frame.origin.x + 48, _name.frame.origin.y, 50, 15);
    _sbjName.frame = CGRectMake(_name.frame.origin.x + 80, _name.frame.origin.y, 50, 15);
    _title.frame = CGRectMake(10, _images.frame.size.height - 80, self.frame.size.width, 20);
    _desc.frame = CGRectMake(12, _images.frame.size.height - 60, self.frame.size.width - 10, 40);
    _ts.frame = CGRectMake(self.frame.size.width - 100, _images.frame.size.height - 30, 90, 20);
    
    _fnum.frame = CGRectMake(_title.frame.origin.x + 20, _images.frame.size.height - 30, 100, 20);
    _cnum.frame = CGRectMake(_fnum.frame.origin.x + 60, _fnum.frame.origin.y, 100, 20);
    _focus.frame = CGRectMake(_fnum.frame.origin.x - 12, _fnum.frame.origin.y + 5, 10, 10);
    _review.frame = CGRectMake(_cnum.frame.origin.x - 12, _cnum.frame.origin.y + 5, 10, 10);
    
    _briImage.frame = _images.bounds;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
